import { ajax } from '../lib/ajax.js';

let text_phone = document.getElementById('text_phone');
let text_password = document.getElementById('text_password');
let text_code = document.getElementById('text_code');
let btnCode = document.getElementById('btnCode');
let btnReg = document.getElementById('btnReg');
let divInfo = document.getElementById('divInfo');

// 发送手机验证码
btnCode.addEventListener('click', () => {
  ajax.post(
    '/tools/sendPhoneCode',
    {
      phone: text_phone.value,
    },
    (data) => {
      divInfo.innerHTML = data.message;
    }
  );
});

// 注册
btnReg.addEventListener('click', () => {
  ajax.post(
    '/user/phone',
    {
      phone: text_phone.value,
      password: text_password.value,
      code: text_code.value,
    },
    (data) => {
      divInfo.innerHTML = data.message;
    }
  );
});
